﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace DMSMT
{
    class Log
    {
        private static Log instance;
        private static RichTextBox logText;
        
        private Log()
        {
        }

        public static void SetInstance(RichTextBox rtBox)
        {
            if (instance == null)
            {
                logText = rtBox;
                instance = new Log();
            }
        }

        private static void Logln(Color color,string text)
        {
            logText.Select(logText.Text.Length, 0);
            logText.SelectionColor = color;
            logText.AppendText(text + "\r\n");
            logText.ScrollToCaret();
        }

        public static void LogError(string text)
        {
            Logln(Color.Red,"错误:\t"+text);
        }

        public static void LogText(string text)
        {
            Logln(Color.Black, text);
        }

        public static void LogWarning(string text)
        {
            Logln(Color.Violet, text);
        }

        internal static void LogError(Exception ex)
        {
            Logln(Color.Red, "错误:\t" + ex.Message);
            Logln(Color.Red, ex.Source);
            Logln(Color.Red, ex.StackTrace.Trim());
            Logln(Color.Red, ex.TargetSite.ToString());
        }
    }
}
